package com.itzjc.config;

import com.itzjc.interceptor.CorsInterceptor;
import com.itzjc.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截配置类
 *
 * @className: InterceptorConfig
 * @date: 2021-06-04 16:45
 **/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    @Bean
    public CorsInterceptor corsInterceptor() {
        return new CorsInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        /**
         *拦截全部路径，需要放到最上面
         **/
        registry.addInterceptor(corsInterceptor()).addPathPatterns("/**");


        //拦截路径匹配注册
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/web/api/v1/pri/*/*/**")
                //不拦截登录、注册、测试方法、忘记密码、所有post请求
                .excludePathPatterns("/web/api/v1/pri/user/login",
                        "/web/api/v1/pri/user/register",
                        "/web/api/v1/pri/user/phoneNumberIsOk",
                        "/web/api/v1/pri/user/findById",
                        "/web/api/v1/pri/user/forget",
                        "/web/api/v1/pri/project/createProjectById",
                        "/web/api/v1/pri/project/uploadFileToCenter",
                        "/web/api/v1/pri/project/rejectCurrentProject",
                        "/web/api/v1/pri/project/sureCurrentProjectStage",
                        "/web/api/v1/pri/upload/uploadImg",
                        "/web/api/v1/pri/upload/uploadDeflectionData",
                        "/web/api/v1/pri/upload/uploadDisplacementData",
                        "/web/api/v1/pri/upload/uploadTemperatureData",
                        "/web/api/v1/pri/upload/uploadStressData",
                        "/web/api/v1/pri/upload/uploadWindData",
                        "/web/api/v1/pri/project/updateProjectImg",
                        "/web/api/v1/pri/project/updateWholeProject",
                        "/web/api/v1/pri/upload/uploadMethod",
                        "/web/api/v1/pri/upload/uploadAgreement",
                        "/web/api/v1/pri/upload/uploadFile",
                        "/web/api/v1/pri/project/updateProjectModule",
                        "/web/api/v1/pri/project/findByIdForSecondSource"

                        );
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
